package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.DataVerification;
import com.ruoyi.system.domain.vo.SysLearningPosterVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysLearningPoster;
import com.ruoyi.system.service.ISysLearningPosterService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 学习海报Controller
 *
 * @author ruoyi
 * @date 2022-04-08
 */
@RestController
@RequestMapping("/system/poster")
public class SysLearningPosterController extends BaseController
{
    @Autowired
    private ISysLearningPosterService sysLearningPosterService;

    /**
     * 查询学习海报列表
     */
    @PreAuthorize("@ss.hasPermi('system:poster:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysLearningPoster sysLearningPoster)
    {
        startPage();
        List<SysLearningPosterVo> list = sysLearningPosterService.selectSysLearningPosterList(sysLearningPoster);
        return getDataTable(list);
    }

    /**
     * 导出学习海报列表
     */
    @PreAuthorize("@ss.hasPermi('system:poster:export')")
    @Log(title = "学习海报", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysLearningPoster sysLearningPoster)
    {
        List<SysLearningPosterVo> list = sysLearningPosterService.selectSysLearningPosterList(sysLearningPoster);
        ExcelUtil<SysLearningPosterVo> util = new ExcelUtil<SysLearningPosterVo>(SysLearningPosterVo.class);
        util.exportExcel(response, list, "学习海报数据");
    }

    /**
     * 获取学习海报详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:poster:query')")
    @GetMapping(value = "/{posterId}")
    public AjaxResult getInfo(@PathVariable("posterId") Long posterId)
    {
        return AjaxResult.success(sysLearningPosterService.selectSysLearningPosterByPosterId(posterId));
    }

    /**
     * 新增学习海报
     */
    @DataVerification(name = "添加学习海报")
    @PreAuthorize("@ss.hasPermi('system:poster:add')")
    @Log(title = "学习海报", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysLearningPoster sysLearningPoster)
    {
        return toAjax(sysLearningPosterService.insertSysLearningPoster(sysLearningPoster));
    }

    /**
     * 修改学习海报
     */
    @DataVerification(name = "修改学习海报")
    @PreAuthorize("@ss.hasPermi('system:poster:edit')")
    @Log(title = "学习海报", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysLearningPoster sysLearningPoster)
    {
        return toAjax(sysLearningPosterService.updateSysLearningPoster(sysLearningPoster));
    }

    /**
     * 删除学习海报
     */
    @PreAuthorize("@ss.hasPermi('system:poster:remove')")
    @Log(title = "学习海报", businessType = BusinessType.DELETE)
	@DeleteMapping("/{posterIds}")
    public AjaxResult remove(@PathVariable Long[] posterIds)
    {
        return toAjax(sysLearningPosterService.deleteSysLearningPosterByPosterIds(posterIds));
    }

    /**
     * 查询学习海报列表
     */
    @GetMapping("/selectList")
    public TableDataInfo selectList(SysLearningPoster sysLearningPoster)
    {
        startPage();
        List<SysLearningPosterVo> list = sysLearningPosterService.selectList(sysLearningPoster);
        return getDataTable(list);
    }
}
